package com.atguigu.mq.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class MyMessageListener {

/*    @RabbitListener(queues = {"atguigu.queue.simple"})
    public void processMessage(String messageContent, Message message, Channel channel) {
        System.out.println("messageContent = " + messageContent);
    }*/

//=========================================================


    //work消息模式下，多个消费者默认是轮询处理消息的。多个消费者之间是竞争关系，不能同时消息到同一个消息。
//多个消费者目的：快速消息队列消息，避免消息积压

   /* @RabbitListener(queues = "atguigu.queue.work")
    public void messageWork1Handler(String msg, Message message, Channel channel){
        System.out.println("work1 msg = " + msg);
    }

    @RabbitListener(queues = "atguigu.queue.work")
    public void messageWork2Handler(String msg, Message message, Channel channel){
        System.out.println("work2 msg = " + msg);
    }*/
    //=========================================================

    /*- 工作队列模式本质上是绑定默认交换机
- 发布订阅模式绑定指定交换机
- 监听同一个队列的消费端程序彼此之间是竞争关系
- 绑定同一个交换机的多个队列在发布订阅模式下，消息是广播的，每个队列都能接收到消息*/



    /*@RabbitListener(queues = {"atguigu.queue.fanout01"})
    public void processMessage01(String messageContent,Message message,Channel channel){
        System.out.println("Consumer01 Message Content:" + messageContent);
    }
    @RabbitListener(queues = {"atguigu.queue.fanout02"})
    public void processMessage02(String messageContent,Message message,Channel channel){
        System.out.println("Consumer02 Message Content:" + messageContent);
    }*/

    //================================================

    /*@RabbitListener(queues = {"atguigu.queue.direct"})
    public void processMessageRouting(String messageContent, Message message, Channel channel) {
        System.out.println("Message Content:" + messageContent);
    }*/

    //=================================================
    @RabbitListener(queues = {"atguigu.queue.message"})
    public void processMessage01(String messageContent, Message message, Channel channel) {
        System.out.println("Queue Message:" + messageContent);
    }

    @RabbitListener(queues = {"atguigu.queue.order"})
    public void processMessage02(String messageContent, Message message, Channel channel) {
        System.out.println("Queue Order:" + messageContent);
    }





}

